<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>Title</title>
    <script src="js/jquery.js"></script>
</head>
<body>
    <h1>添加机房信息页面</h1>
    <form action="computerAdd" method="post">
        <p>机房名称:<input type="text" id="roomName" name="roomName"></p>
        <p>计算机数量:<input type="text" id="computerNumber" name="computerNumber"></p>
        <p>机房管理员:<input type="text" id="manager" name="manager"></p>
        <p>机房地址:<input type="text" id="location" name="location"></p>
        <p>
            机房状态:
            <select name="state" id="state">
                <option value="0">--请选择--</option>
                <option value="1">使用中</option>
                <option value="2">空闲中</option>
                <option value="3">维护中</option>
            </select>
        </p>
        <p>
            相关操作: <input type="submit" value="新增"> <input type="reset">
        </p>
    </form>
</body>
<script>
    $(function (){
        $("form").submit(function (){
            if (checkRoomName()==true && checkComputerNumber()==true && checkLocation()==true && checkManager()==true && checkState()==true){
                alert("新增成功!");
            }else{
                return false;
            }
        })
    })
    function checkRoomName() {
        var roomName = $("#roomName").val();
        if (roomName === "") {alert("机房名称不能为空");return false;}
        return true;
    }
    function checkComputerNumber() {
        var computerNumber = $("#computerNumber").val();
        var aa = /^[1-9]\d*$/
        if (computerNumber === "") {
            alert("机房数量不能为空");
            return false;
        } else if (!aa.test(computerNumber)) {
            alert("请输入大于0的整数");
            return false;
        }
        return true;
    }
    function checkLocation() {
        var location = $("#location").val();
        if (location === "") {alert("机房地址不能为空");return false;}
        return true;
    }
    function checkManager() {
        var manager = $("#manager").val();
        if (manager === "") {alert("管理员不能为空");return false;}
        return true;
    }
    function checkState() {
        var state = $("#state").val();
        if (state === "0") {
            alert("请选择机房状态");
            return false;
        }
        return true;
    }
</script>
</html>
